﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using NewDDSys.Entity;
using NewDDSys.IBLL;
using NewDDSys.IDAL;
using NewDDSys.Factory;
using NewDDSys.Utility;
using NewDDSys.DATAOUT;
using System.IO;
using System.Reflection;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Web_DBZY : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ExcelEdit report = new ExcelEdit();
        report.CreateExcel();
        report.CreateWorkSheet("当班作业情况表");
        report.CellsUnite(1, 1, 1, 17);
        report.WriteData("作业情况记录", 1, 1);
        report.CellsAlignment(1, 1, 1, 17, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        report.WriteData("班别", 2, 1);
        report.WriteData("班组", 2, 2);
        report.WriteData("库区", 2, 3);
        report.WriteData("作业内容", 2, 4);
        report.WriteData("记录吨位", 2, 5);
        report.WriteData("好车数", 2, 6);
        report.WriteData("坏车数", 2, 7);
        report.WriteData("平板数", 2, 8);
        report.WriteData("敞车数", 2, 9);
        report.WriteData("期货车数", 2, 10);
        report.WriteData("货位", 2, 11);
        report.WriteData("空线时间", 2, 12);
        report.WriteData("配到时间", 2, 13);
        report.WriteData("装完时间", 2, 14);
        report.WriteData("封完时间", 2, 15);
        report.WriteData("状态", 2, 16);
        report.WriteData("装完车数", 2, 17);
        DataSet ds = BLLFactory.CreateWorkBLL().DBZY(Session["用户信息.部门"].ToString(), Session["用户信息.班组"].ToString());
        report.WriteData(ds.Tables[0], 2, 17);
        string cday = DateTime.Now.ToShortDateString().ToString();
        string title = Session["用户信息.单位"].ToString() + Session["用户信息.姓名"].ToString() + cday + "当班作业记录";
        string savepath = "sctj\\" + title + ".xls";
        string RepPath = Server.MapPath(savepath);

        report.SaveAs(RepPath); //文档路径
        report.Close();
        string filename = title + ".xls";

        string spath = "sctj\\" + filename;
        string RPath = Server.MapPath(spath);
        FileInfo f = new FileInfo(RPath);
        if (f.Exists)
        {

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
            Response.ContentType = "application/msexcel";
            Response.WriteFile(RPath);
            Response.Flush();
            Response.Close();
            f.Delete();
        }

    }
}
